home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / SC++ 7.0.2 Update / TCL Demos / Art Class ƒ / Art Class Sources / CSelectionRect.cp < prev    next >
Encoding:
Text File  |  1994-04-14  |  3.3 KB  |  114 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  CSelectionRect.c
  3.  
  4.                             The SelectionRect Class
  5.         
  6.     SUPERCLASS = CPaintTask
  7.     
  8.     Copyright © 1989 Symantec Corporation. All rights reserved.
  9.  
  10.  ******************************************************************************/
  11.  
  12. #include "Global.h"
  13. #include "TBUtilities.h"
  14. #include "CSelectionRect.h"
  15.  
  16. /*** Global Variables ***/
  17.  
  18. extern RgnHandle    gUtilRgn;            /* Utility region                    */
  19.  
  20.  
  21. /**** C O N S T R U C T I O N / D E S T R U C T I O N   M E T H O D S ****/
  22.  
  23.  
  24. /******************************************************************************
  25.  CSelectionRect
  26.  
  27.         Initialize a SelectionRect object. There is no task name for a
  28.         selection, since selecting is not undoable.
  29.  ******************************************************************************/
  30.  
  31. CSelectionRect::CSelectionRect(CPaintPane *aPaintPane,CBitMap *aPainting)
  32.                                : CPaintTask(NOTHING, aPaintPane, aPainting)
  33. {}
  34.  
  35.  
  36. /******************************************************************************
  37.  KeepTracking
  38.  ******************************************************************************/
  39.  
  40. void    CSelectionRect::KeepTracking(
  41.     LongPt        *currPt,
  42.     LongPt        *prevPt,
  43.     LongPt        *startPt)
  44. {
  45.     LongRect    currRect;
  46.     LongRect    prevRect;
  47.     RgnHandle    prevRgn;
  48.     RgnHandle    dRgn;
  49.     RgnHandle    oldVis;
  50.     
  51.     oldVis = NewRgn();                    /* Save current visible region in     */
  52.     CopyRgn(qd.thePort->visRgn, oldVis);    /*     case we autoscroll                  */
  53.     
  54.     if (itsPaintPane->AutoScroll(currPt) || !EqualLongPt(currPt, prevPt)) {
  55.         itsPaintPane->GetFrame(&currRect);
  56.         PinInRect(&currRect, currPt);
  57.                                         /* Get current and previous            */
  58.                                         /*   selection rectangles            */
  59.         Pt2LongRect( startPt, currPt, &currRect);
  60.         Pt2LongRect( startPt, prevPt, &prevRect);
  61.         
  62.                                         /* Here we do a lot of work to        */
  63.                                         /*   prevent flashing of the        */
  64.                                         /*   selection rectangle            */
  65.         
  66.         prevRgn = NewRgn();                /* Construct region consisting of a    */
  67.         dRgn = NewRgn();                /*   one pixel thick outline of        */
  68.         LRectRgn(gUtilRgn, &currRect);    /*   the current selection rect        */
  69.         CopyRgn(gUtilRgn, dRgn);
  70.         InsetRgn(dRgn, 1, 1);
  71.         DiffRgn(gUtilRgn, dRgn, gUtilRgn);
  72.         
  73.         LRectRgn(prevRgn, &prevRect);    /* Construct region consisting of a    */
  74.         CopyRgn(prevRgn, dRgn);            /*   one pixel thick outline of        */
  75.         InsetRgn(dRgn, 1, 1);            /*   the previous selection rect    */
  76.         DiffRgn(prevRgn, dRgn, prevRgn);
  77.         SectRgn(prevRgn, oldVis, prevRgn);
  78.         
  79.                                         /* Get region which includes only    */
  80.                                         /*   those pixels that are NOT in    */
  81.                                         /*   both regions                    */
  82.         XorRgn(gUtilRgn, prevRgn, gUtilRgn);
  83.         DisposeRgn(prevRgn);
  84.         DisposeRgn(dRgn);
  85.         
  86.         PenMode(patXor);                /* Paint this new region in gray in    */
  87.         PenPat(&qd.gray);                    /*   Xor mode so pixels are flipped    */
  88.         PaintRgn(gUtilRgn);
  89.     }
  90.     DisposeRgn(oldVis);
  91. }
  92.  
  93.  
  94. /******************************************************************************
  95.  EndTracking
  96.  ******************************************************************************/
  97.  
  98. void    CSelectionRect::EndTracking(
  99.     LongPt        *currPt,
  100.     LongPt        *prevPt,
  101.     LongPt        *startPt)
  102. {
  103.     LongRect    currRect;
  104.     LongRect    prevRect;
  105.  
  106.     KeepTracking(currPt, prevPt, startPt);
  107.     
  108.                                         /* Set the selection rectangle for    */
  109.                                         /*   the PaintPane                    */
  110.     Pt2LongRect( startPt, currPt, &currRect);
  111.     itsPaintPane->selRect = currRect;
  112. }
  113.  
  114.